package com.ys;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @program: note
 * @description:
 * @author:
 * @create 2020-06-11 21:55
 **/
public class ConsumeRecordDaoImpl implements ConsumeRecordDao {
    @Override
    public List<ConsumeRecord> getAll() {
        return ConsumeRecordMapper.getAll();
    }

    @Override
    public List<ConsumeRecord> getAllByType(String type) {
        return getAll().stream()
                .filter(record -> record.getType().equals(type))
                .collect(Collectors.toList());
    }

    @Override
    public void save(ConsumeRecord record) {
        ConsumeRecordMapper.save(record);
    }

    @Override
    public List<ConsumeRecord> getAllBetweenTime(String startTime, String endTime) {
        return getAll().stream()
                .filter(record -> record.getTime().compareTo(startTime) >= 0
                                && record.getTime().compareTo(endTime) <= 0)
                .collect(Collectors.toList());
    }
}
